<template>
  <div class="Home">
    <div class="top">
      <p class="iconfont icon-yuyin" style="font-size: 25px"></p>
      <input type="text" placeholder="请输入内容" @click="toSearch" />
      <p
        class="iconfont icon-paihangbang1"
        style="font-size: 25px"
        @click="toplay()"
      ></p>
    </div>

    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in banners" :key="item.id">
        <img :src="item.pic" :alt="item.name" />
      </van-swipe-item>
    </van-swipe>

    <div class="headr">
      <div class="headr-one">
        <div
          class="icon iconfont icon-tuijian"
          style="font-size: 30px"
          @click="toDetail()"
        ></div>
        <p>每日推荐</p>
      </div>
      <div class="headr-two">
        <div
          class="icon iconfont icon-gedan"
          style="font-size: 30px"
          @click="tosong()"
        ></div>
        <p>歌单</p>
      </div>
      <div class="headr-three">
        <div
          class="icon iconfont icon-paihangbang"
          style="font-size: 30px"
          @click="toRankList()"
        ></div>
        <p>排行榜</p>
      </div>
      <div class="headr-four">
        <div
          class="icon iconfont icon-diantai"
          style="font-size: 30px"
          @click="tovideo()"
        ></div>
        <p>视频</p>
      </div>
    </div>

    <div class="nav">
      <p>推荐歌单</p>
      <p class="nav-2" @click="tosonsing()">歌单广场</p>
    </div>

    <div class="gedan">
      <div
        class="gedan-t"
        v-for="item in Gendan"
        :key="item.id"
        @click="togedan(item.id)"
      >
        <p><img :src="item.coverImgUrl" /></p>
        <p>{{ item.name }}</p>
      </div>
    </div>
    <div class="music">
      <div class="music-left">
        <p>新碟</p>
        <p @click="toXinge()">新歌</p>
      </div>

      <div class="music-right">更多新碟</div>
    </div>
    <div class="gedan">
      <div
        class="gedan-t"
        v-for="item in tuijian"
        :key="item.id"
        @click="togedan(item.id)"
      >
        <p><img :src="item.coverImgUrl" /></p>
        <p>{{ item.name }}</p>
      </div>
    </div>
    <div class="mv">视频</div>
    <div class="videos" @click="toplayvideo(item.id)">
      <div class="video-b" v-for="item in video" :key="item.id">
        <van-cell @click="showPopup">
          <p>{{ item.title }}</p>
          <img :src="item.coverUrl" @click="Play(item.vid)" />
        </van-cell>
        <van-popup v-model="show">
          <video :src="url" autoplay="autoplay" preload controls></video>
        </van-popup>
      </div>
    </div>
    <div style="height: 80px"></div>
  </div>
</template>
<script>
// @ is an alias to /src
import { loadBannersAPI } from "../services/banners";
import { loadGendanAPI } from "../services/gedan";
import { loadTjAPI } from "../services/tuijian";
import { loadvideosAPI } from "../services/videos";
import { videoPlayAPI } from "../services/Video";
import { loadplayvideoAPI } from "../services/videos";

export default {
  name: "Home",
  components: {},
  methods: {
    async Play(v) {
      console.log(v);
      // console.log(v);
      const resPlay = await videoPlayAPI(v);
      this.url = resPlay.urls[0].url;
    },
    showPopup() {
      this.show = true;
    },

    toRankList() {
      this.$router.push({
        name: "RankList",
      });
    },

    togedan(id) {
      this.$router.push({
        name: "TJGD",
        query: { id },
        // sessionStorage.removeItem("id"),
        // sessionStorage.setItem("id",this.id)
      });
    },
    toDetail() {
      this.$router.push({
        name: "detail",
      });
    },
    tosong() {
      this.$router.push({
        name: "Song",
      });
    },
    toplay() {
      this.$router.push({
        name: "Play",
      });
    },
    tovideo() {
      this.$router.push({
        name: "Video",
      });
    },
    toSearch() {
      this.$router.push({
        name: "Search",
      });
    },
    tosonsing() {
      this.$router.push({
        name: "SongSing",
      });
    },
    async toplayvideo(vid) {
      const resplayvideo = await loadplayvideoAPI(vid);
      // this.url = resplayvideo.url[0].url;
      console.log(resplayvideo);
      // console.log(id);
    },
  },
  data() {
    return {
      banners: [],
      Gendan: [],
      tuijian: [],
      video: [],
      show: false,
      url: "",
    };
  },
  async created() {
    const resbanner = await loadBannersAPI();
    const resGendan = await loadGendanAPI();
    const restuijian = await loadTjAPI();
    const resvideo = await loadvideosAPI();

    this.banners = resbanner.banners;
    // console.log(this.banners);
    this.Gendan = resGendan.playlists.slice(1, 7);
    this.tuijian = restuijian.playlists.slice(8, 11);
    this.video = resvideo.data.slice(1.5);

    // console.log(this.Gendan);
  },
};
</script>
<style scoped>
* {
  margin: 0;
  padding: 0;
}
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 10px;
  text-align: center;
  background-color: skyblue;
}
.van-swipe-item img {
  width: 100%;
  height: 100%;
}
.top {
  width: 100%;
  height: 50px;
  display: flex;
  justify-content: space-between;
}
.top p:nth-child(1) {
  text-align: center;
  line-height: 50px;
  width: 40px;
  height: 50px;
}
.top input {
  height: 30px;
  flex: 1;
  border-radius: 30px;
  margin-top: 10px;
  text-align: center;
  background-color: #eeeeee;
  border: 1px solid #eeeeee;
}
.top p:nth-child(3) {
  width: 40px;
  height: 50px;
  text-align: center;
  line-height: 50px;
}
.iconfont {
  align-items: center;

  font-size: 2px;
}
.nav {
  width: 100%;
  height: 60px;
  align-items: center;
  display: flex;
  justify-content: space-between;
}
.nav p:nth-child(1) {
  color: #39a9ed;
  font-weight: bolder;
}
.nav p:nth-child(2) {
  width: 60px;
  height: 20px;
  font-size: 12px;
  color: tomato;
  border-radius: 10px;
  line-height: 20px;
  align-items: center;
  text-align: center;
  border: 1px solid #cecece;
}
.headr {
  display: flex;
  width: 100%;
  height: 80px;
  justify-content: space-between;
}
.headr-one {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 25%;
}
.headr-two {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 25%;
}
.headr-three {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 25%;
}
.headr-four {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 25%;
}
.icon {
  width: 50px;
  height: 50px;
  background-color: skyblue;
  border-radius: 50px;
  text-align: center;
  line-height: 50px;
}
.music {
  width: 100%;
  height: 60px;
  align-items: center;
  display: flex;
  justify-content: space-between;
}
.music-left p:nth-child(1) {
  float: left;
  color: #39a9ed;
  font-weight: bolder;
}
.music-left p {
  float: left;
  padding: 5px;
}
.music-right {
  width: 60px;
  height: 20px;
  font-size: 12px;
  color: tomato;
  border-radius: 10px;
  line-height: 20px;
  align-items: center;
  text-align: center;
  border: 1px solid #cecece;
}
.gedan {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  margin-left: 8px;
}
.gedan-t {
  width: 30%;
  display: flex;
  flex-direction: column;
  padding: 1% 1%;
}
.video-b p:nth-child(1) {
  padding: 5px;
}
.video-b img {
  width: 96%;
  margin-left: 8px;
}
.mv {
  width: 100%;
  height: 40px;
  line-height: 40px;
  margin-left: 8px;
  font-weight: bold;
  color: #39a9ed;
}
video {
  width: 100%;
  height: 300px;
}
</style>
